package com.lottery.ruok.lottrey.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.airbnb.lottie.LottieAnimationView;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.common.Common;
import com.lottery.ruok.lottrey.userInfo.UserInfo;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import utils.Utils;

public class SelectChatActivity extends BaseActivity {


    @BindView(R.id.choose_channel)
    LottieAnimationView chooseChannel;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.close)
    ImageView close;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_chat);
        ButterKnife.bind(this);

        init();
    }

    private void init() {
        if(UserInfo.getChatroom_role() == 1){
            chooseChannel.setAnimation("member/putonghuiyuan/putonghuiyuan.json");
            chooseChannel.setImageAssetsFolder("member/putonghuiyuan/images");
        }
        chooseChannel.playAnimation();
    }

    @OnClick({R.id.view1, R.id.view2, R.id.view3, R.id.close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.view1:
                finish();
                break;
            case R.id.view2:
                if(UserInfo.getChatroom_role() != 1){//管理员
//                    Intent channelInfo = new Intent(this, ChannelInfoActivity.class);
//                    channelInfo.putExtra(ChannelInfoActivity.CHANNEL_KEY, UserInfo.getRoomId());
//                    startActivity(channelInfo);

                    Intent intent = new Intent(SelectChatActivity.this, NewChannelInfoActivity.class);
                    startActivity(intent);
                } else {//管理员列表界面
                    //sendAnalyticMsg("lottery_" + MobiComConversationFragment.ANALYTIC_VERSION + "_chat_group_admin_private_cat");

                    Intent intent = new Intent(SelectChatActivity.this, ChooseManagerActivity.class);
                    startActivity(intent);
                    overridePendingTransition(R.anim.anim_enter_from_bottom, R.anim.activity_stay);
                }
                break;
            case R.id.view3:
//                RetrofitBase.getRetrofit().create(GetServiceMobileRequest.class)
//                        .getResult(UserInfo.getToken())
//                        .compose(RxHelper.<GetServiceMobileResponse>handleResult())
//                        .subscribe(new RxSubscribe<GetServiceMobileResponse>(this) {
//                            @Override
//                            protected void _onNext(GetServiceMobileResponse getServiceMobileResponse) {
//                                Utils.showToast(getApplicationContext(), String.format("前面有%d人正在等待,请等待客服即将给你回电", getServiceMobileResponse.getQueue()));
//                            }
//
//                            @Override
//                            protected boolean showDialog() {
//                                return false;
//                            }
//                        });

//                //打开qq，并跳到客服qq号，这个要申请qq推广
//
//                OkHttpClient client = new OkHttpClient();
//                Request request = new Request.Builder()
//                        .url("https://raw.githubusercontent.com/ruoklive/dynamicdomain/master/qqOutTemp.json")
//                        .build();
//                Call call = client.newCall(request);
//                call.enqueue(new Callback() {
//                    @Override
//                    public void onFailure(Call call, IOException e) {
//                        e.printStackTrace();
//                    }
//
//                    @Override
//                    public void onResponse(Call call, final Response response) throws IOException {
//                        String json = response.body().string();
//                        Gson gson = new Gson();
//                        final QQServiceResponse updateResponse = gson.fromJson(json, QQServiceResponse.class);
//                        if(json != null && updateResponse != null) {
//                            runOnUiThread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    if(Utils.isQQClientAvailable(SelectChatActivity.this)){
//                                        final String qqUrl = String.format("mqqwpa://im/chat?chat_type=wpa&uin=%s&version=1", updateResponse.getQq_number());
//                                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(qqUrl)));
//                                    } else{
//                                        Utils.showToast(getApplicationContext(), "请安装QQ客户端");
//                                    }
//                                }
//                            });
//                        }
//                    }
//                });

//                startActivity(new Intent(this, CustomerServiceActivity.class));

//                getService();

                Utils.openBrowser(Common.service_url, SelectChatActivity.this);
                break;
            case R.id.close:
                finish();
                break;
        }
    }
}
